﻿using System;
using System.Collections;

namespace Csharp进阶_Stack
{
	class Test { }
	class Program
	{
		static void Main(string[] args)
		{
			//Stack st = new Stack();
			//#region 增
			//st.Push(1);
			//st.Push(3.144);
			//st.Push("sadasd");
			//st.Push(new Test());
			//#endregion
			//#region 删
			//st.Pop();
			//#endregion
			//#region 取
			//string s = st.Peek() as string;
			//Console.WriteLine(s);
			//if (st.Contains("sadasd"))
			//{
			//	Console.WriteLine("存在 sadasd");
			//}
			//else
			//{
			//	Console.WriteLine("不存在 sadasd");
			//}
			//#endregion
			//#region 遍历
			//// 从栈顶到栈底
			//foreach (object item in st)
			//{
			//	Console.WriteLine(item);
			//}
			//object[] arr = st.ToArray();
			//for (int i = 0; i < arr.Length; i++)
			//{
			//	Console.WriteLine(arr[i]);
			//}
			//while (st.Count != 0)
			//{
			//	Console.WriteLine(st.Pop());
			//}
			//#endregion
			//#region 增

			//#endregion
			//#region 装箱拆箱
			//int a = 1;
			//st.Push(a);
			//a = (int)st.Pop();
			//#endregion

			//Stack st = new Stack();
			//func(st, 10);
			//print(st);
			Cacl(1);
			Cacl(4);
			Cacl(10);
			Cacl(16);
		}

		static void func(Stack st, int val)
		{
			st.Clear();
			for (int i = 0; i < 32; i++)
			{
				if (((val >> i) & 1) == 1)
				{
					st.Push(1);
				}
				else
				{
					st.Push(0);
				}
			}
		}
		static void print(Stack st)
		{
			foreach (object item in st)
			{
				Console.Write(item);
			}
			Console.WriteLine();
		}

		static void Cacl(uint val)
		{
			uint temp = val;
			Stack st = new Stack();
			while (val != 0)
			{
				st.Push(val % 2);
				val /= 2;
			}
			Console.Write("{0}\t的二进制是\t", temp);
			foreach (object item in st)
			{
				Console.Write(item);
			}
			Console.WriteLine();
		}
	}
}
